package com.ruoyi.whzj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.whzj.domain.WhIntegralHistory;
import com.ruoyi.whzj.service.IWhIntegralHistoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分明细  历史记录Controller
 * 
 * @author ruoyi
 * @date 2020-10-19
 */
@Controller
@RequestMapping("/whzj/history")
public class WhIntegralHistoryController extends BaseController
{
    private String prefix = "whzj/history";

    @Autowired
    private IWhIntegralHistoryService whIntegralHistoryService;

    @RequiresPermissions("whzj:history:view")
    @GetMapping()
    public String history()
    {
        return prefix + "/history";
    }

    /**
     * 查询积分明细  历史记录列表
     */
    @RequiresPermissions("whzj:history:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WhIntegralHistory whIntegralHistory)
    {
        startPage();
        List<WhIntegralHistory> list = whIntegralHistoryService.selectWhIntegralHistoryList(whIntegralHistory);
        return getDataTable(list);
    }

    /**
     * 导出积分明细  历史记录列表
     */
    @RequiresPermissions("whzj:history:export")
    @Log(title = "积分明细  历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WhIntegralHistory whIntegralHistory)
    {
        List<WhIntegralHistory> list = whIntegralHistoryService.selectWhIntegralHistoryList(whIntegralHistory);
        ExcelUtil<WhIntegralHistory> util = new ExcelUtil<WhIntegralHistory>(WhIntegralHistory.class);
        return util.exportExcel(list, "history");
    }

    /**
     * 新增积分明细  历史记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存积分明细  历史记录
     */
    @RequiresPermissions("whzj:history:add")
    @Log(title = "积分明细  历史记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WhIntegralHistory whIntegralHistory)
    {
        return toAjax(whIntegralHistoryService.insertWhIntegralHistory(whIntegralHistory));
    }

    /**
     * 修改积分明细  历史记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WhIntegralHistory whIntegralHistory = whIntegralHistoryService.selectWhIntegralHistoryById(id);
        mmap.put("whIntegralHistory", whIntegralHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存积分明细  历史记录
     */
    @RequiresPermissions("whzj:history:edit")
    @Log(title = "积分明细  历史记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WhIntegralHistory whIntegralHistory)
    {
        return toAjax(whIntegralHistoryService.updateWhIntegralHistory(whIntegralHistory));
    }

    /**
     * 删除积分明细  历史记录
     */
    @RequiresPermissions("whzj:history:remove")
    @Log(title = "积分明细  历史记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(whIntegralHistoryService.deleteWhIntegralHistoryByIds(ids));
    }
}
